package com.rxyb.security.service.logic;

import cn.rxyb.core.date.DateTime;
import cn.rxyb.core.date.enums.FormatDate;
import com.rxyb.security.constants.DbConstant;
import com.rxyb.security.db.po.SysMenuResouce;
import com.rxyb.security.gate.model.AddMenuRoleReq;
import com.rxyb.security.gate.model.MenuListReq;
import com.rxyb.security.gate.model.bean.MenuListBean;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

/**
 * @author YJH
 * @version 1.0
 * @description 菜单业务
 * @date 2020/7/10 10:10
 */
@Component
public class SysMenuResourceLogic {


    /**
     * db 转换成页面需要得数据
     *
     * @param resouce
     * @return
     */
    public MenuListBean dbToModel(SysMenuResouce resouce) {
        MenuListBean bean = new MenuListBean();
        BeanUtils.copyProperties(resouce, bean);
        bean.setAddTime(DateTime.getDateFormat(resouce.getAddTime(), FormatDate.FORMAT_TIME_HOUR_MINUTE_SECOND));
        bean.setUpdateTime(DateTime.getDateFormat(resouce.getUpdateTime(), FormatDate.FORMAT_TIME_HOUR_MINUTE_SECOND));
        return bean;
    }


    /**
     * model 转换 db
     *
     * @param resouce
     * @return
     */
    public SysMenuResouce modelToDb(AddMenuRoleReq req) {
        SysMenuResouce resouce = new SysMenuResouce();
        BeanUtils.copyProperties(req, resouce);
        resouce.setAddTime(DateTime.getDate());
        resouce.setUpdateTime(DateTime.getDate());
        resouce.setRowStatus(DbConstant.ROW_STATE_VALID);
        return resouce;
    }
}
